package com.cmower.dzone.optional;

import java.util.Optional;

public class OrElseOptionalDemo {
public static void main(String[] args) {
//    String name = null;
    String name = "沉默王三";
    System.out.println("orElse");
    String name2 = Optional.ofNullable(name).orElse(getDefaultValue());

    System.out.println("orElseGet");
    String name3 = Optional.ofNullable(name).orElseGet(OrElseOptionalDemo::getDefaultValue);
}

public static String getDefaultValue() {
    System.out.println("getDefaultValue");
    return "沉默王二";
}
}
